package com.ruangong.GitClient.GiteeAPI;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.ruangong.GitClient.R;

import java.util.List;

public class GiteeRepositoryAdapter extends ArrayAdapter<GiteeRepository> {

    private Context mContext;
    private List<GiteeRepository> mRepositories;

    public GiteeRepositoryAdapter(Context context, List<GiteeRepository> repositories) {
        super(context, 0, repositories);
        mContext = context;
        mRepositories = repositories;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View listItem = convertView;
        if (listItem == null) {
            listItem = LayoutInflater.from(mContext).inflate(R.layout.list_item_repository, parent, false);
        }

        GiteeRepository currentRepository = mRepositories.get(position);

        TextView nameTextView = listItem.findViewById(R.id.nameTextView);
        nameTextView.setText(currentRepository.getName());

        TextView ownerTextView = listItem.findViewById(R.id.ownerTextView);
        ownerTextView.setText(currentRepository.getPath());


        return listItem;
    }
}
